<template>
  <div>
    <el-dialog
      title="公告信息"
      :visible.sync="dialogVisible"
      width="800px"
      destroy-on-close
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="名称" prop="name">
              <el-input v-model="form.name" maxlength="100" />
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="正文" prop="content">
              <el-input
                type="textarea"
                :rows="10"
                v-model="form.content"
                maxlength="5000"
                show-word-limit
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { noticeService } from "@/api/sysService";

export default {
  dicts: [],
  components: {},

  data() {
    return {
      resolve: null,
      dialogVisible: false,

      deptOptions: [],
      postOptions: [],
      roleOptions: [],

      // 表单参数
      form: {
        oid: "",

        name: "",
        content: "",
      },

      // 表单校验
      rules: {
        name: [{ required: true, message: "不能为空", trigger: "blur" }],
        content: [{ required: true, message: "不能为空", trigger: "blur" }],
        // component: [{ required: true, message: "不能为空", trigger: "blur" }],
      },
    };
  },

  created() {
    // roleService.list({}).then((res) => {
    //   this.roleOptions = res.data.data;
    // });
  },
  methods: {
    open(row) {
      // const data1 = { username: "John", phone: "123456789" };
      // const { username, phone, role = { id: "1" } } = data1;
      // console.log("test", { username, phone, role });

      this.dialogVisible = true;
      if (row) {
        const { id = "", name = "", content = "" } = row;

        ///

        this.form = {
          content,
          id,
          name,
        };
      }
      return new Promise((resolve) => {
        this.resolve = resolve;
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          noticeService.postSave(this.form).then((response) => {
            this.$modal.msgSuccess("保存成功");
            this.dialogVisible = false;
            this.resolve();
            // this.getList();
          });
        }
      });
    },

    // 取消按钮
    cancel() {
      this.dialogVisible = false;
      this.reset();
    },
  },
};
</script>

<style lang="scss" scoped></style>
